package com.lili.member.service.Impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lili.member.bean.MemberWalletLog;
import com.lili.member.mapper.MemberWalletLogMapper;
import com.lili.member.service.MemberWalletLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

@Service
public class MemberWalletLogServiceImpl implements MemberWalletLogService {

    @Autowired
    MemberWalletLogMapper memberWalletLogMapper;
    @Override
    public int save(MemberWalletLog memberWalletLog) {
        return memberWalletLogMapper.insert(memberWalletLog);
    }

    @Override
    public Page<MemberWalletLog> queryByPage(int current, int pageSize, Map map) {
        Page<MemberWalletLog> page=new Page<>(current,pageSize);
        QueryWrapper<MemberWalletLog> wrapper = new QueryWrapper<>();
        String memberName = (String) map.get("memberName");
        if (!StringUtils.isEmpty(memberName)) {
            wrapper.eq("member_name",memberName);
        }
       if(map.get("startTime")!=null&&map.get("endTime")!=null){
           if (!StringUtils.isEmpty(map.get("startTime").toString()) && !StringUtils.isEmpty(map.get("endTime").toString())) {
               Date startTime =(Date) map.get("startTime");
               Date endTime =(Date) map.get("endTime");
               wrapper.between("create_time",startTime,endTime);
           }
       }
        memberWalletLogMapper.selectPage(page,wrapper);
        return page;
    }
}
